<?php
/**
 * Login_Data_Checkregisterdata
 * check register data
 * @author Adrian Stolarski
 */
class Login_Data_Checkregisterdata implements Login_Data_Mainable, Login_Data_Preparable {
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query
     * database query handler
     */
    public $database_query;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * get data
     * @param array $variables
     * @return type
     */
    public function main(array $variables = null) {
       $this->database->connect();
       foreach ($variables as $key => $value) {
           $variables[$key] = $this->database->escape($value);
       }
       $this->prepare_query($variables);
       $this->database->prepare($this->database_query);
       $this->database->query();
       $user_data = array();
       $user_data = $this->database->fetch('array');
       return $user_data;
    }
    
    /**
     * prepare_query()
     * set query
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        foreach($variables as $key => $value){
            $this->database_query = "SELECT "
                    . "users_data."
                    .$key
                    ." FROM "
                    . "users_data"
                    . " WHERE "
                    . "users_data."
                    .$key
                    ."="
                    .$value
                    ." LIMIT 1;"
                ;
        }
    }

}
